<template>
  <header class="anime-header">
    <div class="logo">
      <img src="@/assets/image/lbt3.png" alt="二次元管理后台">
      <h1>Pink管理后台</h1>
    </div>
    <div class="header-right">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <AvatarImg :size="40" :src="userInfoPink.avatarUrl" />
          <span>{{userInfoPink.username}}</span>
          <el-icon><arrow-down /></el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="个人中心">个人中心</el-dropdown-item>
            <el-dropdown-item command="设置">设置</el-dropdown-item>
            <el-dropdown-item command="退出登录" divided>退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </header>
</template>

<script setup>
import { ArrowDown } from '@element-plus/icons-vue'
import {useRouter} from "vue-router";
import {userInform} from "@/stores/userInform.js";
import AvatarImg from "@/components/AvatarImg.vue";
import {logout} from "@/api/acconut.js";

const userInfoPink = userInform();

const router = useRouter();

const handleCommand = async (command) => {
  if (command === '个人中心') {
    router.push('/admin/adminUser/userInfo');
  }
  if (command === '退出登录') {
    // 执行退出登录操作，例如清除token等
    await logout()
    userInfoPink.clearAll();
    localStorage.removeItem('token');
    router.push('/admin/login');
  }
};
</script>

<style scoped>
.anime-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  height: 60px;
  background-color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.logo {
  display: flex;
  align-items: center;
}

.logo img {
  height: 40px;
  margin-right: 10px;
}

.logo h1 {
  margin: 0;
  font-size: 20px;
  color: #ff6b81;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.header-right {
  display: flex;
  align-items: center;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.el-dropdown-link span {
  margin: 0 5px;
  color: #666;
}
</style>
